/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ruipengkj.bean.TMoneyInOut;
import com.ruipengkj.commons.base.query.BaseQuery;
import com.ruipengkj.commons.base.query.PageModel;
import com.ruipengkj.dao.TMoneyInOutDao;
import com.ruipengkj.service.TMoneyInOutService;
/**
 * 说明：
 * 折扣Service层接口实现
 * @Author：李智深
 * @Date：2012-03-16
 */
@Service
public class TMoneyInOutServiceImpl implements TMoneyInOutService{
	@Resource
	private TMoneyInOutDao TMoneyInOutDao;//DAO层
	//查询所有
	@Override
	public List<TMoneyInOut> findService(TMoneyInOut entity) throws Exception {
		String hql = "select o from TMoneyInOut o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TMoneyInOutDao.findDao(hql, whereHQL.toString(), param, orderby);
	}
	//根据ID翻页查询
	@Override
	public PageModel<TMoneyInOut> getScrollService(int firstResult,
			int maxResult, TMoneyInOut entity) throws Exception {
		String hql = "select o from TMoneyInOut o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getInOutID()!=null&&!entity.getInOutID().equals("")){
				whereHQL.append("InOutID").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getInOutID()+"%");
			}
			if(entity.getOperator()!=null&&!entity.getOperator().equals("")){
				whereHQL.append("Operator").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getOperator()+"%");
			}
			if(entity.getType()!=100){
				whereHQL.append("Type").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getType()+"%");
			}
			if(entity.getSourceType() != 0) {
				whereHQL.append("SourceType=?").append(BaseQuery.AND);
				param.add(entity.getSourceType());
			}
			if(null!=entity.getHappenTime()&&!("").equals(entity.getHappenTime())){
				whereHQL.append("HappenTime>=?").append(BaseQuery.AND);
				param.add(entity.getHappenTime());
			}
			if(null!=entity.getEndTime()&&!("").equals(entity.getEndTime())){
				whereHQL.append("HappenTime<=?").append(BaseQuery.AND);
				param.add(entity.getEndTime());
			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TMoneyInOutDao.getScrollDao(hql, whereHQL.toString(), param, firstResult, maxResult, orderby);
	}
	
	@Override
	public PageModel<TMoneyInOut> getScrollListService(int firstResult,
			int maxResult, TMoneyInOut entity) throws Exception {
		String hql = "select new TMoneyInOut(o.inOutID, o.type, o.personID,"
			+"o.happenTime, o.source, o.sourceType) from TMoneyInOut o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getInOutID()!=null&&!entity.getInOutID().equals("")){
				whereHQL.append("InOutID").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getInOutID()+"%");
			}
			if(entity.getOperator()!=null&&!entity.getOperator().equals("")){
				whereHQL.append("Operator").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getOperator()+"%");
			}
			if(entity.getType()!=100){
				whereHQL.append("Type").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getType()+"%");
			}
			if(entity.getSourceType() != 0) {
				whereHQL.append("SourceType=?").append(BaseQuery.AND);
				param.add(entity.getSourceType());
			}
			if(null!=entity.getHappenTime()&&!("").equals(entity.getHappenTime())){
				whereHQL.append("HappenTime>=?").append(BaseQuery.AND);
				param.add(entity.getHappenTime());
			}
			if(null!=entity.getEndTime()&&!("").equals(entity.getEndTime())){
				whereHQL.append("HappenTime<=?").append(BaseQuery.AND);
				param.add(entity.getEndTime());
			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TMoneyInOutDao.getScrollDao(hql, whereHQL.toString(), param, firstResult, maxResult, orderby);
	}

	//修改
	@Override
	public void modifyService(TMoneyInOut entity) throws Exception {
		TMoneyInOutDao.modifyDao(entity);
		
	}
	//添加
	@Override
	public void saveService(TMoneyInOut entity) throws Exception {
		TMoneyInOutDao.saveDao(entity);
	}
	//根据ID删除
	@Override
	public void deleteService(String id) throws Exception {
		TMoneyInOutDao.deleteDao(id);
		
	}
	//根据ID查询
	@Override
	public TMoneyInOut getByIdService(String id) throws Exception {
		return TMoneyInOutDao.getByIdDao(id);
	}
	//添加或修改
	@Override
	public void saveOrUpdateService(TMoneyInOut entity) throws Exception {
		TMoneyInOutDao.saveOrUpdateDao(entity);
	}
	//添加返回ID
	@Override
	public Serializable saveRetService(TMoneyInOut entity) throws Exception {
		return TMoneyInOutDao.saveRetDao(entity);
	}
	public TMoneyInOutDao getTMoneyInOutDao() {
		return TMoneyInOutDao;
	}

	public void setTMoneyInOutDao(TMoneyInOutDao TMoneyInOutDao) {
		this.TMoneyInOutDao = TMoneyInOutDao;
	}
	
	@Override
	public List<TMoneyInOut> findExportService(
			TMoneyInOut entity) throws Exception {
		String hql = "select o from TMoneyInOut o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getType()!=100){
				whereHQL.append("Type").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getType()+"%");
			}
			if(null!=entity.getHappenTime()&&!("").equals(entity.getHappenTime())){
				whereHQL.append("HappenTime>=?").append(BaseQuery.AND);
				param.add(entity.getHappenTime());
			}
			if(null!=entity.getEndTime()&&!("").equals(entity.getEndTime())){
				whereHQL.append("HappenTime<=?").append(BaseQuery.AND);
				param.add(entity.getEndTime());
			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TMoneyInOutDao.findDao(hql, whereHQL.toString(), param, orderby);
	}
}